<div class="menu" style="margin-top: 120px;">
    <span>添加</span>
</div>
<div class="form">
    <div class="line">
        <span>分类：</span>
        <input id="category_name" type="text" />
        <span id="category_is_private" class="tag" data-val="0">公开</span>
    </div>
    <div class="line">
        <span>&nbsp;</span>
        <a href="javascript:;" id="category_add_save">保存</a>
        <a href="javascript:;" onclick="hideAction()">取消</a>
    </div>
</div>
<script type="text/javascript">
$("#category_is_private").click(function() {
    var $this = $(this);
    if($this.data("val")) {
        $this.data("val", 0);
        $this.html("公开");
    } else {
        $this.data("val", 1);
        $this.html("私有");
    }
});

$("#category_add_save").click(function() {
    el = $(this);
    if(el.data("lock")) return;
    el.data("lock", 1);

    var url = "<!--{:Router::buildUrl('Category_Add')}-->";
    var data = {};
    data.name = $("#category_name").val();
    data.is_private = $("#category_is_private").data("val");
    data._token = get_token();
    $.post(url, data, function(r) {
        alert(r.msg);
        if(r.status) {
            var cid = r.data;
            location.href = "<!--{:Router::buildUrl('User_Index', array('uid' => $mid, 'cid' => '[cid]'))}-->".replace("[cid]", cid);
        }
        el.data("lock", 0);
    }, "json");
});
</script>

